;:sys36864
	;.opt oo
	*= 55296
getx	=$b7f1
bank	=56576
vic	=$d000
screen	=648
tmp	=253	;254
hires	=$a000
xcoord	=$14
konf	=1
rnd	=54299
	sei
	lda #54
	sta konf
	jsr gron
	jsr clr
	lda #255
	sta 54287
	lda #129
	sta 54290
l	jsr line
	jmp l
dx	=2	;3
dy	=4	;5
y2	=6
xwert	=247	;248
rest	=249	;250
xadd	=251	;252
yadd	=255
lin	=167
ywert	=166
x2	=181	;2
rebit	.byt $80,$40,$20,$10,8,4,2,1
dbank	.byt 151,149
dgraf	.byt 27,59
dscre	.byt 4,140
dfind	.byt 23,61
mult	=*
	.word $a000,$a140,$a280,$a3c0
	.word $a500,$a640,$a780,$a8c0
	.word $aa00,$ab40,$ac80,$adc0
	.word $af00,$b040,$b180,$b2c0
	.word $b400,$b540,$b680,$b7c0
	.word $b900,$ba40,$bb80,$bcc0
	.word $be00
gron	=*
	lda #149
	sta bank
	lda #59
	sta vic+17
	lda #140
	sta screen
	sta tmp+1
	lda #61
	sta vic+24
	ldy #0
	sty tmp
	ldx #4
	lda #1
fill	sta (tmp),y
	iny
	bne fill
	inc tmp+1
	dex
	bne fill
	rts
ill	rts
clr	ldy #0
	tya
	sty tmp
	ldx #>hires
	stx tmp+1
	ldx #32
	bne fill
set	cpx #200
	bcs ill
	lda xcoord+1
	cmp #>320
	bcc ok
	bne ill
	lda xcoord
	cmp #<320
	bcs ill
ok	txa
	lsr
	lsr
	lsr
	asl
	tay
	lda mult+1,y
	sta tmp+1
	txa
	and #7
	clc
	adc mult,y
	sta tmp
	lda xcoord
	and #$f8
	adc tmp
	sta tmp
	lda tmp+1
	adc xcoord+1
	sta tmp+1
	lda xcoord
	and #7
	tax
	lda rebit,x
	ldy #0
	eor (tmp),y
	sta (tmp),y
	rts
; linie (xwert/ywert)-(x2/y2)
line	lda rnd
	sta x2
	lda rnd
	sta xwert
ll1	lda rnd
	cmp #200
	bcs ll1
	sta y2
ll2	lda rnd
	cmp #200
	bcs ll2
	sta ywert
	lda rnd
	and #1
	sta x2+1
	lda rnd
	and #1
	sta xwert+1
	sec
	lda x2
	sbc xwert
	sta dx
	lda x2+1
	sbc xwert+1
	sta dx+1
	bpl line1
	eor #-1
	sta dx+1
	lda dx
	eor #-1
	clc
	adc #1
	sta dx
	bcc noinc1
	inc dx+1
noinc1	lda #-1
	sta xadd
	sta xadd+1
	jmp line2
line1	lda #1
	sta xadd
	lda #0
	sta xadd+1
line2	lda dx+1
	bne line3
	lda dx
	bne line3
	lda #0
	.byt $2c
line3	lda #-1
	sta rest
	sta rest+1
	sec
	lda y2
	sbc ywert
	sta dy
	lda #0
	sbc #0
	sta dy+1
	bpl line5
	eor #-1
	sta dy+1
	lda dy
	eor #-1
	clc
	adc #1
	sta dy
	bcc noinc2
	inc dy+1
noinc2	lda #-1
	.byt $2c
line5	lda #1
	sta yadd
	lda dy+1
	cmp dx+1
	bcc line7
	lda dy
	cmp dx
	bcc line7
	lda #-1
	.byt $2c
line7	lda #1
	sta lin
line8	lda xwert
	sta xcoord
	lda xwert+1
	sta xcoord+1
	ldx ywert
	jsr set
line9	lda ywert
	cmp y2
	bne line10
	lda xwert
	cmp x2
	bne line10
	lda xwert+1
	cmp x2+1
	bne line10
	rts
line10	lda rest+1
	bmi zweig1
	sec
	lda rest
	sbc dx
	sta rest
	lda rest+1
	sbc dx+1
	sta rest+1
	clc
	lda ywert
	adc yadd
	sta ywert
	lda lin
	bmi line8
	bpl line9
zweig1	clc
	lda rest
	adc dy
	sta rest
	lda rest+1
	adc dy+1
	sta rest+1
	clc
	lda xwert
	adc xadd
	sta xwert
	lda xwert+1
	adc xadd+1
	sta xwert+1
	lda lin
	bmi line9
	jmp line8
